using CfgTable;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Logic;

namespace IQIGame.Onigao.GamePlay
{
    public sealed class MainCityServiceFactory
    {
        /// 获取服务触发器
        /// </summary>
        /// <param name="triggerID"></param>
        /// <returns></returns>
        public static BaseNonLevelServiceTrigger CreateTrigger(MainCityServiceConfig config)
        {
            BaseNonLevelServiceTrigger trigger = null;
            switch (config.triggerType)
            {
                case MainCityTriggerType.MoveInRange:
                    trigger = ClassPool.Get<TrigMCMoveInRange>();
                    break;
                case MainCityTriggerType.Interact:
                    trigger = ClassPool.Get<TrigMCGeneral>();
                    break;
                default:
                    LogicLog.LogError($"不支持触发类型：{config.triggerType}");
                    break;
            }
            trigger?.Init((int)config.triggerType, config.triggerParams);
            return trigger;
        }

        /// <summary>
        /// 获取服务行为的执行
        /// </summary>
        /// <param name="executionType"></param>
        /// <returns></returns>
        public static BaseNonLevelExecution CreateExecution(CfgNonLevelExecution cfgExecution)
        {
            BaseNonLevelExecution execution = NewExecution(cfgExecution.Type);
            execution?.Init(cfgExecution);
            return execution;
        }

        /// <summary>
        /// 创建exec对象
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static BaseNonLevelExecution NewExecution(int type)
        {
            switch ((NonLevelExecutionType)type)
            {
                case NonLevelExecutionType.Teleport:
                    return ClassPool<ExecMCTeleport>.Get();
                case NonLevelExecutionType.ShowSpeechBubble:
                    return ClassPool<ExecMCShowSpeechBubble>.Get();
                default:
                    //需要服务器来处理的执行，客户端不处理
                    return null;
            }
        }

        public static void ReleaseExecution(BaseNonLevelExecution execution)
        {
            ClassPool.PutAutoType(execution);
        }
    }
}
